package com.springboot.personblogsystem.controller;

import com.springboot.personblogsystem.common.Result;
import com.springboot.personblogsystem.common.req.UserLoginParam;
import com.springboot.personblogsystem.common.req.UserRegisterParam;
import com.springboot.personblogsystem.model.User;
import com.springboot.personblogsystem.service.UserService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 * Description :
 * User: jiume
 * Date: 2025-05-14
 * Time: 8:54
 */
@RequestMapping("/user")
@RestController
public class UserController {

    @Resource
    private UserService userService;

    // 登录接口
    @PostMapping("/login")
    public Result<Boolean> userLogin(@RequestBody UserLoginParam userLoginParam,
                                     HttpSession session) {
        return userService.userLogin(userLoginParam, session);
    }

    // 注册接口
    @PostMapping("/register")
    public Result<Boolean> userRegister(@RequestBody UserRegisterParam userRegisterParam) {
        return userService.userRegister(userRegisterParam);
    }

    // 获取用户个人信息接口
    @GetMapping("/getUserInfo")
    public Result<User> getUserInfo(HttpServletRequest request) {
        return userService.getUserInfo(request);
    }

    // 清除用户登录态
    @DeleteMapping("/deleteUserSession")
    public Result<Boolean> deleteUserSession(HttpServletRequest request) {
        return userService.deleteUserSession(request);
    }
}
